define([ 'handlebars',
		'text!js/home/home.hbs','text!js/home/type-tab.hbs',
		'text!js/home/type-item.hbs','text!js/home/item-content.hbs'], 
	function( Handlebars,source,tabSource,itemSource,itemContent) {
	var $$ = Dom7;

	
	function renderUser(params) {		
		
		if(params.user){
			$('.navbar .center').html( params.user.retData.deptName + ' ' + params.user.retData.name);
		}
		
	}

	//生成内容
	function renderContent(params){
		var template = Handlebars.compile(itemContent);
		var _content = template(params.model);
		
		var _el = $('.home-page ul')
		_el.html(_content);

		bindEvents(params.bindings);
		if(params.f7){
			params.f7.hidePreloader();
		}
	}

	function reRender(params) {
		
		
		if(params.user){
			$('.navbar .center').html( params.user.retData.deptName + ' ' + params.user.retData.name);
		}
		var template = Handlebars.compile(source);	


		var _content = template(params.model);
		$('#homt-type ul').html(_content);
		bindEvents(params.bindings);
	}



	function renderType(params){

		var data = params.model
		//生成tab内容
		var template  = Handlebars.compile(tabSource);
		var _html = template(data)
		_html += '<a href="#more" pcode="more" class="tab-link type-link">更多...</a>'
        $('#home-page .toolbar.tabbar .toolbar-inner').html(_html); 

		
		//生成动画tab
		var template  = Handlebars.compile(itemSource);
		_html = template(data);
		_html += '<div id="more" class="tab"></div>';
        $('#home-page .tabs-animated-wrap .tabs').html(_html);

		bindEvents(params.bindings);
	}

	function bindEvents(bindings) {
		for (var i in bindings) {
			$$(bindings[i].element).on(bindings[i].event, bindings[i].handler);
		}
	}

	return {
		//显示用户
		renderUser		: renderUser ,
		
		//重新加载
		reRender		: reRender,
		//生成tab导航
		renderType		: renderType,

		//生成信息内容
		renderContent	: renderContent
	}
});